package top.humbleyuan.hash;

import java.util.HashMap;

/**
 * @Author HumbleYuan
 * @Date 2020/5/19 20:33
 * @Des 两数之和
 */
public class LeetCode_1 {

    /**
     * 一遍哈希表
     * @param args
     */
    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;

        HashMap<Integer, Integer> map = new HashMap<>();

        for(int i = 0;i < nums.length;i++) {
            int needNum = target - nums[i];
            if(map.containsKey(needNum)) {
                System.out.println(new int[]{i, map.get(needNum)});
            }

            map.put(nums[i], i);
        }

        System.out.println("null");
    }
}
